package http.util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class PackageUtil {  
      
    public static void main(String[] args) {
        String packageName = "http.controller";


//        File f = new File(PackageUtil.class.getResource("/").getPath());

//        File[] childFiles = f.listFiles();
//        for (File childFile : childFiles) {
//            System.out.println(childFile.getName());
//        }


        }
    public static List<String> getClassName(String packageName) {
//        String filePath = ClassLoader.getSystemResource("").getPath() + packageName.replace(".", "\\");
        String classpath = System.getProperty("java.class.path");
        String[] split = classpath.split(";");

        System.out.println(split[0]);
        String filePath =split[0]+File.separator+ packageName.replace(".", "\\");

        List<String> fileNames = getClassName(filePath, null);  
        return fileNames;  
    }  
  
    private static List<String> getClassName(String filePath, List<String> className) {  
        List<String> myClassName = new ArrayList<String>();
        System.out.println("filePath:"+filePath);
        File file = new File(filePath);  
        File[] childFiles = file.listFiles();  
        for (File childFile : childFiles) {  
            if (childFile.isDirectory()) {  
                myClassName.addAll(getClassName(childFile.getPath(), myClassName));  
            } else {  
                String childFilePath = childFile.getPath();
                if(childFilePath.contains("$")){
                    continue;
                }
                childFilePath = childFilePath.substring(childFilePath.indexOf("\\classes") + 9, childFilePath.lastIndexOf("."));
                childFilePath = childFilePath.replace("\\", ".");  
                myClassName.add(childFilePath);  
            }  
        }  
  
        return myClassName;  
    }  
}  